package com.aw.guiguzi.util

import android.content.Context
import android.graphics.Typeface
import android.os.Build
import android.text.SpannableString
import android.text.Spanned
import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan
import androidx.annotation.RequiresApi
import com.aw.baselib.bean.CommonImgItemBean
import com.aw.baselib.util.AwConvertUtil
import com.aw.baselib.util.AwDataUtil
import com.aw.baselib.util.AwLog
import com.aw.guiguzi.R
import com.aw.guiguzi.bean.AnalysisDataResultBean
import com.aw.guiguzi.bean.AnalysisSuggestResultBean
import com.aw.guiguzi.bean.CalSuggestItemBean
import com.aw.guiguzi.bean.NumEncloseBean
import com.aw.guiguzi.bean.TransactionItemBean
import com.aw.guiguzi.constants.MyConstant
import com.aw.guiguzi.enums.CombinationTagEnums
import com.aw.guiguzi.enums.NumEnums
import com.aw.guiguzi.enums.NumEnums.Companion.getBlock
import com.aw.guiguzi.enums.TrendTagEnums
import java.util.Locale
import java.util.regex.Pattern

object DataUtil {
    @JvmField
    var calIntervalNum = AppCacheUtil.getCalIntervalNum()
    val defaultTransactionList: List<TransactionItemBean>
        /**
         * 生成默认的交易列表数据, 用于配置
         * @return
         */
        get() {
            val list: MutableList<TransactionItemBean> = ArrayList()
            for (i in 0..5) {
                val imgList: MutableList<CommonImgItemBean> = ArrayList()
                imgList.add(CommonImgItemBean("", ""))
                imgList.add(CommonImgItemBean("", ""))
                imgList.add(CommonImgItemBean("", ""))
                list.add(TransactionItemBean("", imgList))
            }
            return list
        }
    val allNumEncloseList: MutableList<NumEncloseBean>
        get() {
            val list: MutableList<NumEncloseBean> = ArrayList()
            for (i in 0..9) {
                list.add(NumEncloseBean(i))
            }
            return list
        }
    val allNumList: List<Int>
        get() = ArrayList(listOf(*arrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)))

    fun generateAllBlockForRemove(): MutableList<Int> {
        return ArrayList(listOf(*arrayOf(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)))
    }

    val allTrendList: MutableList<CalSuggestItemBean>
        get() {
            val list: MutableList<CalSuggestItemBean> = ArrayList()
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND1_1_1,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND1_1_1.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND1_1_2,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND1_1_2.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND1_2_1,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND1_2_1.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND1_2_2,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND1_2_2.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND1_3_1,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND1_3_1.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND1_3_2,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND1_3_2.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND1_4_1,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND1_4_1.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND1_4_2,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND1_4_2.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND2_1_1,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND2_1_1.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND2_1_2,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND2_1_2.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND2_2_1,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND2_2_1.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND2_2_2,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND2_2_2.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND3_1_1,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND3_1_1.code)
                )
            )
            list.add(
                CalSuggestItemBean(
                    TrendTagEnums.TREND3_1_2,
                    AppCacheUtil.isTrendActive(TrendTagEnums.TREND3_1_2.code)
                )
            )
            return list
        }

    fun getAnalysisResultList(
        type: String,
        currentNumList: MutableList<Int>
    ): MutableList<AnalysisDataResultBean?> {
        val calResultStrList: MutableList<AnalysisDataResultBean?> = ArrayList()
        if (type == TrendTagEnums.TREND1_1_1.type) {
            val resultBeanAdd1 = analysisDataAdd(currentNumList as MutableList<Int>, 3) //加法1
            val resultBeanAdd1_2 = analysisDataAdd(currentNumList, 2)
            val resultBeanAdd2 = analysisDataAdd2(currentNumList, 3) //加法2
            val resultBeanAdd2_2 = analysisDataAdd2(currentNumList, 2)
            val resultBeanAdd3 = analysisDataAdd3(currentNumList, 3) //加法3
            val resultBeanAdd3_2 = analysisDataAdd3(currentNumList, 2)
            val resultBeanAdd4 = analysisDataAdd4(currentNumList, 4) //加法4
            val resultBeanAdd4_2 = analysisDataAdd4(currentNumList, 3)
            calResultStrList.add(resultBeanAdd1)
            calResultStrList.add(resultBeanAdd1_2)
            calResultStrList.add(resultBeanAdd2)
            calResultStrList.add(resultBeanAdd2_2)
            calResultStrList.add(resultBeanAdd3)
            calResultStrList.add(resultBeanAdd3_2)
            calResultStrList.add(resultBeanAdd4)
            calResultStrList.add(resultBeanAdd4_2)
        } else if (type == TrendTagEnums.TREND2_1_1.type) {
            val resultBeanSubtract1 = analysisDataSubtract(currentNumList as MutableList<Int>, 3) //减法1
            val resultBeanSubtract1_2 = analysisDataSubtract(currentNumList, 2)
            val resultBeanSubtract2 = analysisDataSubtract2(currentNumList, 3) //减法2
            val resultBeanSubtract2_2 = analysisDataSubtract2(currentNumList, 2)
            calResultStrList.add(resultBeanSubtract1)
            calResultStrList.add(resultBeanSubtract1_2)
            calResultStrList.add(resultBeanSubtract2)
            calResultStrList.add(resultBeanSubtract2_2)
        } else if (type == TrendTagEnums.TREND3_1_1.type) {
            val resultBeanMultiply1 = analysisDataMultiply(currentNumList as MutableList<Int>, 3) //乘法1
            val resultBeanMultiply1_2 = analysisDataMultiply(currentNumList, 2)
            calResultStrList.add(resultBeanMultiply1)
            calResultStrList.add(resultBeanMultiply1_2)
        } else if (type == TrendTagEnums.TREND_COMMON.type) {
            calResultStrList.add(analysisDataSingleEven(currentNumList)) //单双
            calResultStrList.add(analysisDataBigSmall(currentNumList)) //大小
            calResultStrList.add(analysisDataRedYellow(currentNumList)) //颜色
            calResultStrList.add(analysisDataMidEdge(currentNumList)) //中间数边缘数
        }
        //        else if(type.equals(TREND0_2_1.type)) {
//        } else if(type.equals(TREND0_3_1.type)) {
//        }
//        AwLog.d("getAnalysisResultList: " + calResultStrList.toString());
        return calResultStrList
    }

    fun getTrendEnumsList(type: String): List<TrendTagEnums> {
        val trendTagEnumsList: MutableList<TrendTagEnums> = ArrayList()
        if (type == TrendTagEnums.TREND1_1_1.type) {
            trendTagEnumsList.add(TrendTagEnums.TREND1_1_1)
            trendTagEnumsList.add(TrendTagEnums.TREND1_1_2)
            trendTagEnumsList.add(TrendTagEnums.TREND1_2_1)
            trendTagEnumsList.add(TrendTagEnums.TREND1_2_2)
            trendTagEnumsList.add(TrendTagEnums.TREND1_3_1)
            trendTagEnumsList.add(TrendTagEnums.TREND1_3_2)
            trendTagEnumsList.add(TrendTagEnums.TREND1_4_1)
            trendTagEnumsList.add(TrendTagEnums.TREND1_4_2)
        } else if (type == TrendTagEnums.TREND2_1_1.type) {
            trendTagEnumsList.add(TrendTagEnums.TREND2_1_1)
            trendTagEnumsList.add(TrendTagEnums.TREND2_1_2)
            trendTagEnumsList.add(TrendTagEnums.TREND2_2_1)
            trendTagEnumsList.add(TrendTagEnums.TREND2_2_2)
        } else if (type == TrendTagEnums.TREND3_1_1.type) {
            trendTagEnumsList.add(TrendTagEnums.TREND3_1_1)
            trendTagEnumsList.add(TrendTagEnums.TREND3_1_2)
        } else if (type == TrendTagEnums.TREND_COMMON.type) {
            trendTagEnumsList.add(TrendTagEnums.TREND0_1_1)
            trendTagEnumsList.add(TrendTagEnums.TREND0_2_1)
            trendTagEnumsList.add(TrendTagEnums.TREND0_3_1)
            trendTagEnumsList.add(TrendTagEnums.TREND0_4_1)
        }
        //        else if(type.equals(TREND0_2_1.type)) {
//            trendTagEnumsList.add(TREND0_2_1);
//            trendTagEnumsList.add(TREND0_2_2);
//        } else if(type.equals(TREND0_3_1.type)) {
//            trendTagEnumsList.add(TREND0_3_1);
//            trendTagEnumsList.add(TREND0_3_2);
//        }
        return trendTagEnumsList
    }

    val combinationEnumsList: List<CombinationTagEnums>
        get() {
            val list: MutableList<CombinationTagEnums> = ArrayList()
            list.add(CombinationTagEnums.COMBINATION_1)
            list.add(CombinationTagEnums.COMBINATION_2)
            list.add(CombinationTagEnums.COMBINATION_3)
            list.add(CombinationTagEnums.COMBINATION_4)
            return list
        }

    /**
     * 添加符号
     * @param input 字符串内容
     * @param n 间隔几位数
     * @param separator 符号
     * @return
     */
    fun addSeparator(input: String?, n: Int, separator: String): String {
        val builder = StringBuilder(input)
        var index = n
        while (index < builder.length) {
            builder.insert(index, separator)
            index += n + separator.length
        }
        return builder.toString()
    }

    fun addSeparator(input: String, separator: Char): String {
        val sb = StringBuilder()
        val length = input.length
        for (i in 0 until length) {
            val c = input[i]
            // 判断是否为数字，避免在非数字位置加符号
            if (c >= '0' && c <= '9') {
                sb.append(c)
                // 当不是最后一位且下一位也是数字时，添加分隔符
                if (i < length - 1 && input[i + 1] >= '0' && input[i + 1] <= '9') {
                    sb.append(separator)
                }
            }
        }
        return sb.toString()
    }

    fun isNumeric(str: String): Boolean {
        var temp = 0
        for (i in 0 until str.length) {
            //判断不能含有多个小数点
            if (str[i] == '.' && temp == 0) {
                temp++
                continue
            } //判断字符串的每一个字符不能为数字以外的字符
            if (!Character.isDigit(str[i])) {
                return false
            } //判断字符串的最后一位不能为小数点
            if (str[str.length - 1] == '.') {
                return false
            }
        }
        return true
    }

    /**
     * 匹配指定关键字
     * @param color
     * @param text
     * @param keyword
     * @return
     */
    fun matcherSearchText(
        color: Int,
        text: String,
        keyword: String,
        needOtherStyle: Boolean
    ): SpannableString {
        val string = text.lowercase(Locale.getDefault())
        val key = keyword.lowercase(Locale.getDefault())
        val pattern = Pattern.compile(key)
        val matcher = pattern.matcher(string)
        val ss = SpannableString(text)
        while (matcher.find()) {
            val start = matcher.start()
            val end = matcher.end()

            // 色值
            ss.setSpan(
                ForegroundColorSpan(color), start, end,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
            )
            if (needOtherStyle) {
                // 加粗
                val boldSpan = StyleSpan(Typeface.BOLD)
                ss.setSpan(
                    boldSpan, start, end,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                )
                // 斜体
                val italicSpan = StyleSpan(Typeface.ITALIC)
                ss.setSpan(
                    italicSpan, start, end,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                )
            }
        }
        return ss
    }

    /**
     * 匹配多个指定关键字
     * @param color
     * @param text
     * @param keywords
     * @return
     */
    fun matcherSearchText(
        color: Int,
        text: String,
        keywords: Array<String>,
        needOtherStyle: Boolean
    ): SpannableString {
        val ss = SpannableString(text)
        for (keyword in keywords) {
            val string = text.lowercase(Locale.getDefault())
            val key = keyword.lowercase(Locale.getDefault())
            val pattern = Pattern.compile(key)
            val matcher = pattern.matcher(string)
            while (matcher.find()) {
                val start = matcher.start()
                val end = matcher.end()
                // 色值
                ss.setSpan(
                    ForegroundColorSpan(color), start, end,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                )
                if (needOtherStyle) {
                    // 加粗
                    val boldSpan = StyleSpan(Typeface.BOLD)
                    ss.setSpan(
                        boldSpan, start, end,
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                    )
                    // 斜体
                    val italicSpan = StyleSpan(Typeface.ITALIC)
                    ss.setSpan(
                        italicSpan, start, end,
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                    )
                }
            }
        }
        return ss
    }

    /**
     * 匹配多个指定关键字, 不同的数组不同的样式
     * @param color
     * @param text
     * @param keywords
     * @return
     */
    fun matcherSearchTextDiffArea(
        text: String,
        color: Int,
        keywords: Array<String>,
        needOtherStyle: Boolean,
        color2: Int,
        keywords2: Array<String>,
        needOtherStyle2: Boolean
    ): SpannableString {
        val ss = SpannableString(text)
        for (keyword in keywords) {
            val string = text.lowercase(Locale.getDefault())
            val key = keyword.lowercase(Locale.getDefault())
            val pattern = Pattern.compile(key)
            val matcher = pattern.matcher(string)
            while (matcher.find()) {
                val start = matcher.start()
                val end = matcher.end()
                // 色值
                ss.setSpan(
                    ForegroundColorSpan(color), start, end,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                )
                if (needOtherStyle) {
                    // 加粗
                    val boldSpan = StyleSpan(Typeface.BOLD)
                    ss.setSpan(
                        boldSpan, start, end,
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                    )
                    // 斜体
                    val italicSpan = StyleSpan(Typeface.ITALIC)
                    ss.setSpan(
                        italicSpan, start, end,
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                    )
                }
            }
        }
        for (keyword in keywords2) {
            val string = text.lowercase(Locale.getDefault())
            val key = keyword.lowercase(Locale.getDefault())
            val pattern = Pattern.compile(key)
            val matcher = pattern.matcher(string)
            while (matcher.find()) {
                val start = matcher.start()
                val end = matcher.end()
                // 色值
                ss.setSpan(
                    ForegroundColorSpan(color2), start, end,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                )
                if (needOtherStyle2) {
                    // 加粗
                    val boldSpan = StyleSpan(Typeface.BOLD)
                    ss.setSpan(
                        boldSpan, start, end,
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                    )
                    // 斜体
                    val italicSpan = StyleSpan(Typeface.ITALIC)
                    ss.setSpan(
                        italicSpan, start, end,
                        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                    )
                }
            }
        }
        return ss
    }

    /**
     * 匹配多个指定关键字
     * @param color
     * @param text
     * @param keywords
     * @return
     */
    fun matcherSearchTextScreenOutPre(
        color: Int,
        text: String,
        keywords: Array<String>
    ): SpannableString {
        val ss = SpannableString(text)
        for (keyword in keywords) {
            val string = text.lowercase(Locale.getDefault())
            val key = keyword.lowercase(Locale.getDefault())
            val pattern = Pattern.compile(key)
            val matcher = pattern.matcher(string)
            while (matcher.find()) {
                val start = matcher.start()
                val end = matcher.end()
                // 色值
                ss.setSpan(
                    ForegroundColorSpan(color), start, end,
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
                )
            }
        }
        if (AppCacheUtil.isNumsScreenOutPre() && text.length > AppCacheUtil.getAnalysisNumsScreenOutPreCustom()) {
            // 加粗
            val boldSpan = StyleSpan(Typeface.BOLD)
            ss.setSpan(
                boldSpan, AppCacheUtil.getAnalysisNumsScreenOutPreCustom(), text.length,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
            )
            // 斜体
            val italicSpan = StyleSpan(Typeface.ITALIC)
            ss.setSpan(
                italicSpan, AppCacheUtil.getAnalysisNumsScreenOutPreCustom(), text.length,
                Spanned.SPAN_EXCLUSIVE_EXCLUSIVE
            )
        }
        return ss
    }

    /**
     * 判断大值(传参字符串, 取重复出现次数最多的)
     * @param str
     * @param subStr1
     * @param subStr2
     * @return
     */
    fun judgeGreater(str: String, subStr1: String, subStr2: String): Boolean {
        return countOccurrences(str, subStr1) > countOccurrences(str, subStr2)
    }

    /**
     * 判断大值(传参list集合)
     * @param list1
     * @param list2
     * @return
     */
    fun judgeGreater(list1: List<Int?>, list2: List<Int?>): Boolean {
        return list1.size > list2.size
    }

    /**
     * 指定字符串出现次数
     * @param originalString
     * @param substring
     * @return
     */
    fun countOccurrences(originalString: String, substring: String): Int {
        var count = 0
        var index = originalString.indexOf(substring)
        while (index != -1) {
            count++
            index = originalString.indexOf(substring, index + substring.length)
        }
        return count
    }

    /**
     * 指定集合数据转字符串拼接
     * @param list
     * @return
     */
    fun getDesignatedNums(list: MutableList<Int>): String {
        if (AwDataUtil.isEmpty(list)) {
            return ""
        }
        val numbers: MutableSet<Int?> = HashSet()
        val sb = StringBuffer()
        for (temp in list) {
            numbers.add(temp)
        }
        for (temp in numbers) {
            sb.append(temp)
        }
        return sb.toString()
    }

    /**
     * 获取当前版面所有 大数 数量
     * @return
     */
    fun getBigNumCount(currentNumList: MutableList<Int>): MutableList<Int> {
        val list: MutableList<Int> = ArrayList()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.BIG.block.contains(temp)) {
                    list.add(temp)
                }
            }
        }
        return list
    }

    /**
     * 获取当前版面所有 小数 数量
     * @return
     */
    fun getSmallNumCount(currentNumList: MutableList<Int>): MutableList<Int> {
        val list: MutableList<Int> = ArrayList()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.SMALL.block.contains(temp)) {
                    list.add(temp)
                }
            }
        }
        return list
    }

    /**
     * 获取当前版面所有 奇数 数量
     * @return
     */
    fun getSingularNumCount(currentNumList: MutableList<Int>): MutableList<Int> {
        val list: MutableList<Int> = ArrayList()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.SINGULAR.block.contains(temp)) {
                    list.add(temp)
                }
            }
        }
        return list
    }

    /**
     * 获取当前版面所有 偶数 数量
     * @return
     */
    fun getEvenNumCount(currentNumList: MutableList<Int>): MutableList<Int> {
        val list: MutableList<Int> = ArrayList()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.EVEN.block.contains(temp)) {
                    list.add(temp)
                }
            }
        }
        return list
    }

    /**
     * 获取当前版面所有号
     * @return
     */
    fun getDashboardNumStr(allNumStr: String): String {
        var allNumStr = allNumStr
        if (!AwDataUtil.isEmpty(allNumStr)) {
            if (allNumStr.length > 15) {
                allNumStr = allNumStr.substring(allNumStr.length - 15, allNumStr.length)
            }
            return allNumStr
        }
        return allNumStr
    }

    /**
     * 获取当前版面所有 冷号
     * @return
     */
    fun getColdNumList(currentNumList: MutableList<Int>): MutableList<Int> {
        var currentNumList = currentNumList
        if (!AwDataUtil.isEmpty(currentNumList)) {
            if (currentNumList.size > 15) {
                currentNumList =
                    currentNumList.subList(currentNumList.size - 15, currentNumList.size)
            }
            val list = generateAllBlockForRemove()
            list.removeAll(currentNumList)
            return list
        }
        return ArrayList()
    }

    /**
     * 获取当前版面所有 跳区间数
     * @return
     */
    fun getJumpNumList(mSortNumList: MutableList<Int>?): MutableList<Int> {
        if (!AwDataUtil.isEmpty(mSortNumList)) {
            val list = generateAllBlockForRemove()
            list.removeAll(mSortNumList!!)
            return list
        }
        return ArrayList()
    }

    /**
     * 获取当前版面所有 热号
     * @return
     */
    fun getHotNumStr(currentNumList: MutableList<Int>): MutableList<String> {
        val list: MutableList<String> = ArrayList()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            val map: MutableMap<Int?, Int> = HashMap()
            for (temp in currentNumList) {
                var i = 1 //定义一个计数器，用来记录重复数据的个数
                if (map[temp] != null) {
                    i = map[temp]!! + 1
                }
                map[temp] = i
            }
            list.add(map.toString())
            var max = 0
            var keySb = StringBuffer()
            for ((key, value) in map) {
                if (value > max) {
                    max = value
                    keySb = StringBuffer()
                    keySb.append(key).append(",")
                } else if (value == max) {
                    keySb.append(key).append(",")
                }
            }
            list.add("最热号：" + keySb.substring(0, keySb.length - 1) + "(" + max + "次)")
            val keySet: MutableSet<String> = HashSet()
            for ((key) in map) {
                keySet.add(key.toString())
            }
            list.add(keySet.toString())
        }
        return list
    }

    /**
     * 获取当前版面所有 红色区域号
     * @return
     */
    fun getNumList_red(currentNumList: MutableList<Int>): MutableList<Int> {
        val list: MutableList<Int> = ArrayList()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.RED.block.contains(temp)) {
                    list.add(temp)
                }
            }
        }
        return list
    }

    /**
     * 获取当前版面所有 红色区域号
     * @return
     */
    fun getNumList_yellows(currentNumList: MutableList<Int>): MutableList<Int> {
        val list: MutableList<Int> = ArrayList()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.YELLOW.block.contains(temp)) {
                    list.add(temp)
                }
            }
        }
        return list
    }

    /**
     * 获取当前版面所有 红黄数区分
     * @return
     */
    fun getColorNumStr(currentNumList: MutableList<Int>): String {
        val sb = StringBuffer()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.YELLOW.block.contains(temp)) {
                    sb.append("黄")
                } else {
                    sb.append("红")
                }
            }
        }
        return sb.toString()
    }

    /**
     * 获取当前版面所有 大小数区分
     * @return
     */
    fun getBigAndSmallNumStr(currentNumList: MutableList<Int>): String {
        val sb = StringBuffer()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.BIG.block.contains(temp)) {
                    sb.append("大")
                } else {
                    sb.append("小")
                }
            }
        }
        return sb.toString()
    }

    /**
     * 获取当前版面所有 单双数区分
     * @return
     */
    fun getSingularAndEvenNumStr(currentNumList: MutableList<Int>): String {
        val sb = StringBuffer()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.EVEN.block.contains(temp)) {
                    sb.append("双")
                } else {
                    sb.append("单")
                }
            }
        }
        return sb.toString()
    }

    /**
     * 获取当前版面所有 中间数和边缘数区分
     * @return
     */
    fun getMidEdgeNumStr(currentNumList: MutableList<Int>): String {
        val sb = StringBuffer()
        if (!AwDataUtil.isEmpty(currentNumList)) {
            for (temp in currentNumList) {
                if (NumEnums.MIDDLE.block.contains(temp)) {
                    sb.append("中")
                } else {
                    sb.append("偏")
                }
            }
        }
        return sb.toString()
    }

    /**
     * 对比数量多的字符串(顺跳走势)，建议值（总长度大于10的时候， 数量差值 >= 8, 总长度小于等于10的时候， 数量差值 >=4)
     * @param isJump 是否是判断“跳”
     * @param originStr 待分析的顺跳走势字符串
     * @return
     */
    fun getBetterTrends(isJump: Boolean, originStr: String): Boolean {
        if (AwDataUtil.isEmpty(originStr)) {
            return false
        }
        AwLog.d("getBetterTrends isJump: $isJump ,originStr: $originStr")
        return if (AppCacheUtil.isUseBetterTrendsPercent()) {
            AwLog.d("执行择优比重 isJump: $isJump ,originStr: $originStr")
            var isPass = false
            var countStr = originStr
            if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
                if (originStr.length > AppCacheUtil.getAnalysisLengthCustom()) {
                    countStr =
                        countStr.substring(countStr.length - AppCacheUtil.getAnalysisLengthCustom())
                }
            } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
                if (originStr.length > AppCacheUtil.getLimitStatisticsCountCustom()) {
                    //开启了限制统计数量长度， 并且当前已有数值长度大于自定义设置的数量
                    countStr = originStr.substring(
                        originStr.length - AppCacheUtil.getLimitStatisticsCountCustom(),
                        originStr.length
                    )
                }
            }
            AwLog.d("执行择优比重 过滤长度后countStr: $countStr")
            val jumpSizeOrigin = countOccurrences(countStr, "跳")
            val sortSizeOrigin = countOccurrences(countStr, "顺")
            AwLog.d("执行择优比重, countStr length: " + countStr.length + ",jumpSizeOrigin: " + jumpSizeOrigin + " ,sortSizeOrigin: " + sortSizeOrigin + " ,percent: " + AppCacheUtil.getBetterTrendsPercent())
            //启用了择优比重, 则不考虑其他差值
            isPass = if (jumpSizeOrigin > sortSizeOrigin) {
                AwLog.d(
                    "执行择优比重, jumpSizeOrigin > sortSizeOrigin percent: " + AwConvertUtil.div(
                        jumpSizeOrigin.toDouble(),
                        countStr.length.toDouble(),
                        2
                    ) * 100
                )
                if (AwConvertUtil.div(
                        jumpSizeOrigin.toDouble(),
                        countStr.length.toDouble(),
                        2
                    ) * 100 >= AppCacheUtil.getBetterTrendsPercent()
                ) {
                    true
                } else {
                    false
                }
            } else if (jumpSizeOrigin < sortSizeOrigin) {
                AwLog.d(
                    "执行择优比重, jumpSizeOrigin < sortSizeOrigin percent: " + AwConvertUtil.div(
                        sortSizeOrigin.toDouble(),
                        countStr.length.toDouble(),
                        2
                    ) * 100
                )
                if (AwConvertUtil.div(
                        sortSizeOrigin.toDouble(),
                        countStr.length.toDouble(),
                        2
                    ) * 100 >= AppCacheUtil.getBetterTrendsPercent()
                ) {
                    true
                } else {
                    false
                }
            } else {
                AwLog.d(
                    "执行择优比重, jumpSizeOrigin = sortSizeOrigin percent: " + AwConvertUtil.div(
                        jumpSizeOrigin.toDouble(),
                        countStr.length.toDouble(),
                        2
                    ) * 100
                )
                if (AwConvertUtil.div(
                        jumpSizeOrigin.toDouble(),
                        countStr.length.toDouble(),
                        2
                    ) * 100 >= AppCacheUtil.getBetterTrendsPercent()
                ) {
                    true
                } else {
                    false
                }
            }
            AwLog.d("执行择优比重, 结果: $isPass")
            isPass && isJump
        } else {
            var countStr = originStr
            var isOriginPass = false
            var isPre15Pass = false
            var isLimitAnalysisLengthPass = false
            var isCalLimitPass = false
            if (AppCacheUtil.isAnalaysisModel2()) {
                if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
                    if (originStr.length > AppCacheUtil.getAnalysisLengthCustom()) {
                        //开启了限制统计数量长度， 并且当前已有数值长度大于自定义设置的数量
                        countStr = originStr.substring(
                            originStr.length - AppCacheUtil.getAnalysisLengthCustom(),
                            originStr.length
                        )
                    }
                } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
                    if (originStr.length > AppCacheUtil.getLimitStatisticsCountCustom()) {
                        //开启了限制统计数量长度， 并且当前已有数值长度大于自定义设置的数量
                        countStr = originStr.substring(
                            originStr.length - AppCacheUtil.getLimitStatisticsCountCustom(),
                            originStr.length
                        )
                    }
                }
                val jumpSize = countOccurrences(countStr, "跳")
                val sortSize = countOccurrences(countStr, "顺")
                AwLog.d("getBetterTrends countStr: $countStr \njumpSize: $jumpSize ,sortSize: $sortSize")
                if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
                    isCalLimitPass = judgeIsPass(
                        isJump,
                        AppCacheUtil.getCalLengthDifferenceLimitAnalaysis(),
                        jumpSize,
                        sortSize
                    )
                } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2 || countStr.length < 15) {
                    isCalLimitPass = judgeIsPass(
                        isJump,
                        AppCacheUtil.getCalLengthDifferenceLimitStatistics(),
                        jumpSize,
                        sortSize
                    )
                }
            } else {
                val jumpSizeOrigin = countOccurrences(countStr, "跳")
                val sortSizeOrigin = countOccurrences(countStr, "顺")
                //所有数字
                isOriginPass = judgeIsPass(
                    isJump,
                    AppCacheUtil.getCalLengthDifferenceAll(),
                    jumpSizeOrigin,
                    sortSizeOrigin
                )

                //筛除前15
                if (countStr.length > 25) {
                    //如果开启了前15位过滤且总长度大于25位, 以该过滤为准
                    val countStrPre = countStr.substring(15)
                    //计算过滤后前15位后所有数值的次数
                    val jumpSizePre15 = countOccurrences(countStrPre, "跳")
                    val sortSizePre15 = countOccurrences(countStrPre, "顺")
                    isPre15Pass = judgeIsPass(
                        isJump,
                        AppCacheUtil.getCalLengthDifferencePre15(),
                        jumpSizePre15,
                        sortSizePre15
                    )
                }
                if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT1) {
                    if (originStr.length > AppCacheUtil.getAnalysisLengthCustom()) {
                        val countStrLimitAnalysisLength =
                            countStr.substring(countStr.length - AppCacheUtil.getAnalysisLengthCustom())
                        val jumpSizeLimitAnalysisLength =
                            countOccurrences(countStrLimitAnalysisLength, "跳")
                        val sortSizeLimitAnalysisLength =
                            countOccurrences(countStrLimitAnalysisLength, "顺")
                        isLimitAnalysisLengthPass = judgeIsPass(
                            isJump,
                            AppCacheUtil.getCalLengthDifferenceLimitAnalaysis(),
                            jumpSizeLimitAnalysisLength,
                            sortSizeLimitAnalysisLength
                        )
                    }
                } else if (AppCacheUtil.getLimitType() == MyConstant.SWITCH_LIMIT2) {
                    if (originStr.length > AppCacheUtil.getLimitStatisticsCountCustom()) {
                        //开启了限制统计数量长度， 并且当前已有数值长度大于自定义设置的数量
                        val countStrLimitStatistics = originStr.substring(
                            originStr.length - AppCacheUtil.getLimitStatisticsCountCustom(),
                            originStr.length
                        )
                        val jumpSizeLimitStatistics =
                            countOccurrences(countStrLimitStatistics, "跳")
                        val sortSizeLimitStatistics =
                            countOccurrences(countStrLimitStatistics, "顺")
                        AwLog.d("getBetterTrends countStr: $countStrLimitStatistics \njumpSizeLimitStatistics: $jumpSizeLimitStatistics ,sortSizeLimitStatistics: $sortSizeLimitStatistics")
                        isCalLimitPass = judgeIsPass(
                            isJump,
                            AppCacheUtil.getCalLengthDifferenceLimitStatistics(),
                            jumpSizeLimitStatistics,
                            sortSizeLimitStatistics
                        )
                    }
                }
            }
            AwLog.d("getBetterTrends ---> \nisOriginPass: $isOriginPass ,isPre15Pass: $isPre15Pass ,isLimitAnalysisLengthPass: $isLimitAnalysisLengthPass ,isCalLimitPass: $isCalLimitPass")
            if (isOriginPass || isPre15Pass || isLimitAnalysisLengthPass || isCalLimitPass) {
                true
            } else {
                false
            }
        }
    }

    /**
     * 各种条件判断
     * @param isJump 是否是跳
     * @param judgeCount 判断最低数量
     * @param jumpSize 跳的数量
     * @param sortSize 顺的数量
     * @return
     */
    private fun judgeIsPass(
        isJump: Boolean,
        judgeCount: Int,
        jumpSize: Int,
        sortSize: Int
    ): Boolean {
        //所有数字
        return if (isJump) {
            if (jumpSize - sortSize >= judgeCount) {
                true
            } else {
                false
            }
        } else {
            if (sortSize - jumpSize >= judgeCount) {
                true
            } else {
                false
            }
        }
    }

    fun getBetterTrends(tag: String?, list: MutableList<Int>): Boolean {
        val bigCount = getBigNumCount(list).size
        val smallCount = getSmallNumCount(list).size
        val singularCount = getSingularNumCount(list).size
        val evenCount = getEvenNumCount(list).size
        val redCount = getNumList_red(list).size
        val yellowCount = getNumList_yellows(list).size
        if (AppCacheUtil.getLimitType() != MyConstant.SWITCH_ALL || list.size < 15) {
            when (tag) {
                "单" -> return if (singularCount - evenCount >= AppCacheUtil.getCalLengthDifferenceLimitStatistics()) {
                    true
                } else {
                    false
                }

                "双" -> return if (evenCount - singularCount >= AppCacheUtil.getCalLengthDifferenceLimitStatistics()) {
                    true
                } else {
                    false
                }

                "大" -> return if (bigCount - smallCount >= AppCacheUtil.getCalLengthDifferenceLimitStatistics()) {
                    true
                } else {
                    false
                }

                "小" -> return if (smallCount - bigCount >= AppCacheUtil.getCalLengthDifferenceLimitStatistics()) {
                    true
                } else {
                    false
                }

                "红" -> return if (redCount - yellowCount >= AppCacheUtil.getCalLengthDifferenceLimitStatistics()) {
                    true
                } else {
                    false
                }

                "黄" -> return if (yellowCount - redCount >= AppCacheUtil.getCalLengthDifferenceLimitStatistics()) {
                    true
                } else {
                    false
                }
            }
        } else {
            when (tag) {
                "单" -> return if (singularCount - evenCount >= AppCacheUtil.getCalLengthDifferenceLimitAnalaysis()) {
                    true
                } else {
                    false
                }

                "双" -> return if (evenCount - singularCount >= AppCacheUtil.getCalLengthDifferenceLimitAnalaysis()) {
                    true
                } else {
                    false
                }

                "大" -> return if (bigCount - smallCount >= AppCacheUtil.getCalLengthDifferenceLimitAnalaysis()) {
                    true
                } else {
                    false
                }

                "小" -> return if (smallCount - bigCount >= AppCacheUtil.getCalLengthDifferenceLimitAnalaysis()) {
                    true
                } else {
                    false
                }

                "红" -> return if (redCount - yellowCount >= AppCacheUtil.getCalLengthDifferenceLimitAnalaysis()) {
                    true
                } else {
                    false
                }

                "黄" -> return if (yellowCount - redCount >= AppCacheUtil.getCalLengthDifferenceLimitAnalaysis()) {
                    true
                } else {
                    false
                }
            }
        }
        return false
    }

    /**
     * 对比设置数量多的颜色值
     * @param context
     * @param list1
     * @param list2
     * @return
     */
    fun getBetterColor(context: Context, list1: List<Int?>, list2: List<Int?>): Int {
        return getBetterColor(context, list1.size, list2.size)
    }

    /**
     * 对比设置数量多的颜色值
     * @param context
     * @param size1
     * @param size2
     * @return
     */
    fun getBetterColor(context: Context, size1: Int, size2: Int): Int {
        return if (size1 > size2) {
            context.resources.getColor(com.aw.baselib.R.color.orange)
        } else {
            context.resources.getColor(R.color.black)
        }
    }

    /**
     * 判断指定数字是否在组合内
     * @param type
     * @param number
     * @return
     */
    fun isSpecialBlock(type: Int, number: Int): Boolean {
        val specialList = getBlock(type)
        return specialList.contains(number)
    }

    /**
     * 判断是否匹配组合
     * @param type
     * @param currentNumList
     * @return
     */
    fun isMatchBlock(type: Int, currentNumList: List<Int>): Boolean {
        var isMatch = true
        if (!AwDataUtil.isEmpty(currentNumList) && currentNumList.size > 2) {
            for (i in currentNumList.size - 1 downTo currentNumList.size - 2) {
                if (!isSpecialBlock(type, currentNumList[i])) {
                    isMatch = false
                    break
                }
            }
        } else {
            isMatch = false
        }
        return isMatch
    }

    /**
     * 获取当前版面所有 下轮建议数字
     * @return
     */
    @RequiresApi(api = Build.VERSION_CODES.N)
    fun getSuggestNumList(currentNumList: MutableList<Int>): MutableList<Int> {
        val list = generateAllBlockForRemove()
        //大小数过滤
        if (getBigNumCount(currentNumList).size - getSmallNumCount(currentNumList).size > 3) {
//            list.removeIf(smallNumList::contains);
            list.removeAll(NumEnums.SMALL.block)
        } else if (getSmallNumCount(currentNumList).size - getBigNumCount(currentNumList).size > 3) {
            list.removeAll(NumEnums.BIG.block)
        }
        //单双数过滤
        if (getSingularNumCount(currentNumList).size - getEvenNumCount(currentNumList).size > 3) {
            list.removeAll(NumEnums.EVEN.block)
        } else if (getEvenNumCount(currentNumList).size - getSingularNumCount(currentNumList).size > 3) {
            list.removeAll(NumEnums.SINGULAR.block)
        }
        //红黄数过滤
        if (getNumList_red(currentNumList).size - getNumList_yellows(currentNumList).size > 3) {
            list.removeAll(NumEnums.YELLOW.block)
        } else if (getNumList_yellows(currentNumList).size - getNumList_red(currentNumList).size > 3) {
            list.removeAll(NumEnums.RED.block)
        }
        return list
    }

    /**
     * 获取当前版面所有 下轮建议数字
     * @return
     */
    fun getSuggestResultBean(
        colorNumStr: String,
        bigAndSmallNumStr: String,
        singularAndEvenNumStr: String
    ): AnalysisSuggestResultBean {
        val resultBean = AnalysisSuggestResultBean()
        val list: MutableList<Int> = generateAllBlockForRemove()
        val sb = StringBuffer()
        //如果颜色超过连续的最大值, 则建议另一个色值
        if (isAccordCondition(colorNumStr, "黄")) {
            list.removeAll(NumEnums.YELLOW.block)
            sb.append("红").append(",")
        } else if (isAccordCondition(colorNumStr, "红")) {
            list.removeAll(NumEnums.RED.block)
            sb.append("黄").append(",")
        }
        if (sb != null && sb.length > 0) {
            AwLog.d("判断是否满足条件颜色 SB: $sb ,list: $list")
        }
        //如果大小超过连续的最大值, 则建议另一个值
        if (isAccordCondition(bigAndSmallNumStr, "大")) {
            list.removeAll(NumEnums.BIG.block)
            sb.append("小").append(",")
        } else if (isAccordCondition(bigAndSmallNumStr, "小")) {
            list.removeAll(NumEnums.SMALL.block)
            sb.append("大").append(",")
        }
        if (sb != null && sb.length > 0) {
            AwLog.d("判断是否满足条件大小 SB: $sb ,list: $list")
        }
        //如果单双超过连续的最大值, 则建议另一个值
        if (isAccordCondition(singularAndEvenNumStr, "单")) {
            list.removeAll(NumEnums.SINGULAR.block)
            sb.append("双").append(",")
        } else if (isAccordCondition(singularAndEvenNumStr, "双")) {
            list.removeAll(NumEnums.EVEN.block)
            sb.append("单").append(",")
        }
        if (sb != null && sb.length > 0) {
            AwLog.d("判断是否满足条件单双 SB: $sb ,list: $list")
        }
        //        resultBean.setDescs(sb.toString().substring(0, sb.length() - 1));
//        resultBean.setResultList(list);
        return resultBean
    }

    /**
     * 判断是否满足条件 (如"黄"达到最大值, 则返回true, 其他红大小单双类似)
     * @param originStr 待判断的字符串
     * @param accordStr 拆选的字符串关键字
     * @return
     */
    fun isAccordCondition(originStr: String, accordStr: String): Boolean {
        AwLog.d("======== 判断是否满足条件 ========")
        AwLog.d("判断是否满足条件 originStr: $originStr ,accordStr: $accordStr")
        if (originStr.endsWith(accordStr)) {
            AwLog.d("判断是否满足条件 endsWith true")
            val count = getMaxRepeatedCount(originStr, accordStr)
            AwLog.d("判断是否满足条件 getMaxRepeatedCount count: $count")
            val sb = StringBuffer()
            for (i in 0 until count) {
                sb.append(accordStr)
            }
            AwLog.d("判断是否满足条件: $sb")
            AwLog.d("判断是否满足条件, 最后存在位置lastIndexOf: " + originStr.lastIndexOf(sb.toString()) + " ,缩位: " + (originStr.length - count))
            if (originStr.lastIndexOf(sb.toString()) == originStr.length - count) {
                return true
            }
        }
        return false
    }

    /**
     * 判断结尾是 顺或跳连续的数量是否满足 阈值
     * @param str 跳变字符串数组
     * @param key 判断的关键字
     * @return
     */
    fun judgeJumpSmoothlyMaxCountEndStr(str: String, key: String?): Boolean {
        if (AwDataUtil.isEmpty(str) || !AwDataUtil.isEmpty(key) && !str.endsWith(key!!)) {
            return false
        }
        val arrs = str.split("".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
        val endStr = arrs[arrs.size - 1]
        var count = 0
        for (i in arrs.size downTo 1) {
            if (arrs[i - 1] == endStr) {
                count++
            } else {
                break
            }
        }
        return if (count >= AppCacheUtil.getCalEndLength()) {
            true
        } else {
            false
        }
    }

    /**
     * 获取 各跳变类型 连续出现的最大值
     * @param str 跳变字符串数组
     * @return
     */
    fun getEveryJumpSmoothlyMaxCountStr(str: String): String {
        val sb = StringBuffer()
        if (str == null) {
            return "--"
        }
        for (i in str.indices) {
            val temp = str[i]
            AwLog.d("getEveryJumpSmoothlyMaxCountStr str: $temp")
            if (AwDataUtil.isEmpty(temp)) {
                continue
            }
            val smoothlyName = "顺" + (i + 1) + ": "
            val jumpName = "跳" + (i + 1) + ": "
            //走势1
            sb.append(smoothlyName).append(getMaxRepeatedCount(temp.toString(), "顺")).append("次, ")
            sb.append(jumpName).append(getMaxRepeatedCount(temp.toString(), "跳")).append("次; ")
        }
        return sb.toString()
    }

    /**
     * 获取 各跳变类型 连续出现的最大值
     * @param strList 跳变字符串集合
     * @return
     */
    fun getEveryJumpSmoothlyMaxCountStr(strList: List<String>?): String {
        val sb = StringBuffer()
        if (strList == null) {
            return "--"
        }
        for (i in strList.indices) {
            val temp = strList[i]
            AwLog.d("getEveryJumpSmoothlyMaxCountStr str: $temp")
            if (AwDataUtil.isEmpty(temp)) {
                continue
            }
            val smoothlyName = "顺" + (i + 1) + ": "
            val jumpName = "跳" + (i + 1) + ": "
            //走势1
            sb.append(smoothlyName).append(getMaxRepeatedCount(temp, "顺")).append("次, ")
            sb.append(jumpName).append(getMaxRepeatedCount(temp, "跳")).append("次; ")
        }
        return sb.toString()
    }

    /**
     * 获取 各类型 连续出现的最大值
     * @param colorNumStr
     * @param bigAndSmallNumStr
     * @param singularAndEvenNumStr
     * @return
     */
    fun getEveryMaxCountStr(
        colorNumStr: String,
        bigAndSmallNumStr: String,
        singularAndEvenNumStr: String
    ): String {
        AwLog.d("getEveryMaxCountStr colorNumStr: $colorNumStr ,bigAndSmallNumStr: $bigAndSmallNumStr ,singularAndEvenNumStr: $singularAndEvenNumStr")
        val sb = StringBuffer()
        sb.append(getSingleMaxCountStr(colorNumStr, "红"))
        sb.append(getSingleMaxCountStr(colorNumStr, "黄"))
        sb.append(getSingleMaxCountStr(bigAndSmallNumStr, "大"))
        sb.append(getSingleMaxCountStr(bigAndSmallNumStr, "大"))
        sb.append(getSingleMaxCountStr(singularAndEvenNumStr, "单"))
        sb.append(getSingleMaxCountStr(singularAndEvenNumStr, "双"))
        return sb.toString()
    }

    /**
     * 获取 单类型 某个关键字 连续出现的最大值
     * @param originStr
     * @param accordStr
     * @return
     */
    fun getSingleMaxCountStr(originStr: String?, accordStr: String): String {
        return accordStr + ": " + getMaxRepeatedCount(originStr, accordStr) + "次, "
    }

    /**
     * 获取指定字符串连续出现的最大值
     * @param str
     * @param subStr
     * @return
     */
    fun getMaxRepeatedCount(str: String?, subStr: String?): Int {
        var subStr = subStr
        if (str == null || subStr == null || str.length == 0 || subStr.length == 0) {
            return 0
        }
        if (subStr.length > 1) {
            subStr = subStr.substring(0, subStr.length - 1)
        }
        AwLog.d("getMaxRepeatedCount str: $str ,subStr: $subStr")
        var maxCount = 0
        var currentCount = 0
        val length = subStr.length
        var prePosition = 0 //之前一个存在数字的index位置
        var i = 0
        while (i < str.length) {
            val index = str.indexOf(subStr, i)
            AwLog.d("getMaxRepeatedCount index: $index ,i: $i ,currentCount: $currentCount ,maxCount: $maxCount ,prePosition: $prePosition")
            if (index == i) {
                AwLog.d("getMaxRepeatedCount index == i")
                if (index - prePosition > 1) {
                    AwLog.d("超过1位， 非连续的， 重置当前计数")
                    //超过1位， 非连续的， 重置当前计数
                    currentCount = 1
                } else {
                    currentCount++
                    i += length - 1 // 跳过已匹配的子字符串
                    //                    if(index == str.length() -1) {
//                        //已遍历到最后一位。直接赋值
//                        maxCount = currentCount;
//                    }
                }
                prePosition = index
            } else if (currentCount > maxCount) {
                AwLog.d("getMaxRepeatedCount currentCount > maxCount")
                maxCount = currentCount
            } else {
                AwLog.d("getMaxRepeatedCount else ...")
                currentCount = 0
            }
            i++
        }
        return if (maxCount > currentCount) maxCount else currentCount
    }

    /**
     * 转换面板数字为集合
     * @param calNums
     * @return
     */
    fun getCurrentNumsList(calNums: String): MutableList<Int> {
        val list: MutableList<Int> = ArrayList()
        for (i in 0 until calNums.length) {
            //组装所有数字集合
            list.add(AwDataUtil.getIntValue(calNums[i].toString()))
        }
        return list
    }

    /**
     * 计算逻辑 (加法), 临近2轮数字相加, 大于10 减掉10 取差值(即取个位数)
     * @param currentNumsList 当前数字集合
     * @param limitMinNums 3 前推一位数后的最近2位数相加 2 当前最近2位数相加
     * @return
     */
    fun analysisDataAdd(currentNumsList: MutableList<Int>, limitMinNums: Int): AnalysisDataResultBean? {
        AwLog.d("================ 计算逻辑 (加法1) =================")
        AwLog.d("加法 限制最少数字数量: $limitMinNums")
        if (currentNumsList.size < limitMinNums) {
            //小于limitMinNums个数, 不处理
            return null
        }
        var sortNumsList: MutableList<Int> = ArrayList() //顺数字集合
        val calResultList: MutableList<String> = ArrayList() //顺跳结果集合
        for (i in 0 until currentNumsList.size - limitMinNums + 1) {
            AwLog.d("加法 i: " + i + " ,数1: " + currentNumsList[i] + " ,数2: " + currentNumsList[i + 1])
            var pre2Sum = currentNumsList[i] + currentNumsList[i + 1] //8 4 12
            if (pre2Sum >= 10) {
                pre2Sum = pre2Sum - 10 //2
            }
            val minSuggestValue =
                if (pre2Sum - calIntervalNum < 0) pre2Sum + 10 - calIntervalNum else pre2Sum - calIntervalNum //7
            val maxSuggestValue =
                if (pre2Sum + calIntervalNum >= 10) pre2Sum + calIntervalNum - 10 else pre2Sum + calIntervalNum //1
            AwLog.d("加法 i: $i ,pre2Sum: $pre2Sum ,minSuggestValue: $minSuggestValue ,maxSuggestValue: $maxSuggestValue")
            sortNumsList = ArrayList()
            if (minSuggestValue > maxSuggestValue) {
                AwLog.d("加法 minSuggestValue > maxSuggestValue")
                for (j in minSuggestValue..10) {
                    if (j == 10) {
                        sortNumsList.add(0)
                    } else {
                        sortNumsList.add(j)
                    }
                }
                for (k in 0..maxSuggestValue) {
                    sortNumsList.add(k)
                }
            } else if (minSuggestValue < maxSuggestValue) {
                AwLog.d("加法 minSuggestValue < maxSuggestValue")
                for (j in minSuggestValue..maxSuggestValue) {
                    sortNumsList.add(j)
                }
            } else {
                AwLog.d("加法 minSuggestValue = maxSuggestValue")
                for (j in minSuggestValue - calIntervalNum..maxSuggestValue + calIntervalNum) {
                    sortNumsList.add(j)
                }
            }
            if (i < currentNumsList.size - limitMinNums) {
                var isExist = false
                val nextValue = currentNumsList[i + limitMinNums]
                AwLog.d("加法 i: $i ,nextValue: $nextValue")
                for (temp in sortNumsList) {
                    if (temp == nextValue) {
                        isExist = true
                        break
                    }
                }
                calResultList.add(if (isExist) "顺" else "跳")
            }
        }
        val sb = StringBuffer()
        for (temp in calResultList) {
            sb.append(temp)
        }
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = sb.toString()
        resultBean.sortNumsList = sortNumsList
        return resultBean
    }

    /**
     * 计算逻辑 (加法), 临近2轮数字相加, 结果大于10, 两位数继续相加
     * @param currentNumsList 当前数字集合
     * @param limitMinNums 3 前推一位数后的最近2位数相加 2 当前最近2位数相加
     * @return
     */
    fun analysisDataAdd2(currentNumsList: List<Int>, limitMinNums: Int): AnalysisDataResultBean? {
        AwLog.d("================ 计算逻辑 (加法2) =================")
        AwLog.d("加法 限制最少数字数量: $limitMinNums")
        if (currentNumsList.size < limitMinNums) {
            //小于limitMinNums个数, 不处理
            return null
        }
        var sortNumsList: MutableList<Int> = ArrayList() //顺数字集合
        val calResultList: MutableList<String> = ArrayList() //顺跳结果集合
        for (i in 0 until currentNumsList.size - limitMinNums + 1) {
            AwLog.d("加法 i: " + i + " ,数1: " + currentNumsList[i] + " ,数2: " + currentNumsList[i + 1])
            var pre2Sum = currentNumsList[i] + currentNumsList[i + 1]
            if (pre2Sum >= 10) {
                pre2Sum = AwDataUtil.getIntValue(
                    pre2Sum.toString().split("".toRegex()).dropLastWhile { it.isEmpty() }
                        .toTypedArray()[0]) + AwDataUtil.getIntValue(
                    pre2Sum.toString().split("".toRegex()).dropLastWhile { it.isEmpty() }
                        .toTypedArray()[1])
            }
            val minSuggestValue =
                if (pre2Sum - calIntervalNum < 0) pre2Sum + 10 - calIntervalNum else pre2Sum - calIntervalNum //7
            val maxSuggestValue =
                if (pre2Sum + calIntervalNum >= 10) pre2Sum + calIntervalNum - 10 else pre2Sum + calIntervalNum //1
            AwLog.d("加法 i: $i ,pre2Sum: $pre2Sum ,minSuggestValue: $minSuggestValue ,maxSuggestValue: $maxSuggestValue")
            sortNumsList = ArrayList()
            if (minSuggestValue > maxSuggestValue) {
                AwLog.d("加法 minSuggestValue > maxSuggestValue")
                for (j in minSuggestValue..10) {
                    if (j == 10) {
                        sortNumsList.add(0)
                    } else {
                        sortNumsList.add(j)
                    }
                }
                for (k in 0..maxSuggestValue) {
                    sortNumsList.add(k)
                }
            } else if (minSuggestValue < maxSuggestValue) {
                AwLog.d("加法 minSuggestValue < maxSuggestValue")
                for (j in minSuggestValue..maxSuggestValue) {
                    sortNumsList.add(j)
                }
            } else {
                AwLog.d("加法 minSuggestValue = maxSuggestValue")
                for (j in minSuggestValue - calIntervalNum..maxSuggestValue + calIntervalNum) {
                    sortNumsList.add(j)
                }
            }
            if (i < currentNumsList.size - limitMinNums) {
                var isExist = false
                val nextValue = currentNumsList[i + limitMinNums]
                AwLog.d("加法 i: $i ,nextValue: $nextValue")
                for (temp in sortNumsList) {
                    if (temp == nextValue) {
                        isExist = true
                        break
                    }
                }
                calResultList.add(if (isExist) "顺" else "跳")
            }
        }
        val sb = StringBuffer()
        for (temp in calResultList) {
            sb.append(temp)
        }
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = sb.toString()
        resultBean.sortNumsList = sortNumsList
        return resultBean
    }

    /**
     * 计算逻辑 (先加后减), 临近2轮数字相加, 结果大于10, 用个位或十位的 大值减去小值
     * @param currentNumsList 当前数字集合
     * @param limitMinNums 3 前推一位数后的最近2位数相加 2 当前最近2位数相加
     * @return
     */
    fun analysisDataAdd3(currentNumsList: List<Int>, limitMinNums: Int): AnalysisDataResultBean? {
        AwLog.d("================ 计算逻辑 (加法3) =================")
        AwLog.d("加法 限制最少数字数量: $limitMinNums")
        if (currentNumsList.size < limitMinNums) {
            //小于limitMinNums个数, 不处理
            return null
        }
        var sortNumsList: MutableList<Int> = ArrayList() //顺数字集合
        val calResultList: MutableList<String> = ArrayList() //顺跳结果集合
        for (i in 0 until currentNumsList.size - limitMinNums + 1) {
            AwLog.d("加法 i: " + i + " ,数1: " + currentNumsList[i] + " ,数2: " + currentNumsList[i + 1])
            var pre2Sum = currentNumsList[i] + currentNumsList[i + 1]
            if (pre2Sum >= 10) {
                pre2Sum = if (AwDataUtil.getIntValue(
                        pre2Sum.toString().split("".toRegex()).dropLastWhile { it.isEmpty() }
                            .toTypedArray()[0]) < AwDataUtil.getIntValue(
                        pre2Sum.toString().split("".toRegex()).dropLastWhile { it.isEmpty() }
                            .toTypedArray()[1])
                ) {
                    AwDataUtil.getIntValue(
                        pre2Sum.toString().split("".toRegex()).dropLastWhile { it.isEmpty() }
                            .toTypedArray()[1]
                    ) - AwDataUtil.getIntValue(
                        pre2Sum.toString().split("".toRegex()).dropLastWhile { it.isEmpty() }
                            .toTypedArray()[0]
                    )
                } else {
                    AwDataUtil.getIntValue(
                        pre2Sum.toString().split("".toRegex()).dropLastWhile { it.isEmpty() }
                            .toTypedArray()[0]) - AwDataUtil.getIntValue(
                        pre2Sum.toString().split("".toRegex()).dropLastWhile { it.isEmpty() }
                            .toTypedArray()[1])
                }
            }
            val minSuggestValue =
                if (pre2Sum - calIntervalNum < 0) pre2Sum + 10 - calIntervalNum else pre2Sum - calIntervalNum //7
            val maxSuggestValue =
                if (pre2Sum + calIntervalNum >= 10) pre2Sum + calIntervalNum - 10 else pre2Sum + calIntervalNum //1
            AwLog.d("加法 i: $i ,pre2Sum: $pre2Sum ,minSuggestValue: $minSuggestValue ,maxSuggestValue: $maxSuggestValue")
            sortNumsList = ArrayList()
            if (minSuggestValue > maxSuggestValue) {
                AwLog.d("加法 minSuggestValue > maxSuggestValue")
                for (j in minSuggestValue..10) {
                    if (j == 10) {
                        sortNumsList.add(0)
                    } else {
                        sortNumsList.add(j)
                    }
                }
                for (k in 0..maxSuggestValue) {
                    sortNumsList.add(k)
                }
            } else if (minSuggestValue < maxSuggestValue) {
                AwLog.d("加法 minSuggestValue < maxSuggestValue")
                for (j in minSuggestValue..maxSuggestValue) {
                    sortNumsList.add(j)
                }
            } else {
                AwLog.d("加法 minSuggestValue = maxSuggestValue")
                for (j in minSuggestValue - calIntervalNum..maxSuggestValue + calIntervalNum) {
                    sortNumsList.add(j)
                }
            }
            if (i < currentNumsList.size - limitMinNums) {
                var isExist = false
                val nextValue = currentNumsList[i + limitMinNums]
                AwLog.d("加法 i: $i ,nextValue: $nextValue")
                for (temp in sortNumsList) {
                    if (temp == nextValue) {
                        isExist = true
                        break
                    }
                }
                calResultList.add(if (isExist) "顺" else "跳")
            }
        }
        val sb = StringBuffer()
        for (temp in calResultList) {
            sb.append(temp)
        }
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = sb.toString()
        resultBean.sortNumsList = sortNumsList
        return resultBean
    }

    /**
     * 计算逻辑 (加法), 临近3轮数字相加, 大于10 减掉10 取差值(即取个位数)
     * @param currentNumsList 当前数字集合
     * @param limitMinNums 3 前推一位数后的最近3位数相加 2 当前最近3位数相加
     * @return
     */
    fun analysisDataAdd4(currentNumsList: List<Int>, limitMinNums: Int): AnalysisDataResultBean? {
        AwLog.d("================ 计算逻辑 (加法4) =================")
        AwLog.d("加法 限制最少数字数量: $limitMinNums")
        if (currentNumsList.size < limitMinNums) {
            //小于limitMinNums个数, 不处理
            return null
        }
        var sortNumsList: MutableList<Int> = ArrayList() //顺数字集合
        val calResultList: MutableList<String> = ArrayList() //顺跳结果集合
        for (i in 0 until currentNumsList.size - limitMinNums + 1) { //1 2 3 4 5 6 7 8 9
            AwLog.d("加法 i: " + i + " ,数1: " + currentNumsList[i] + " ,数2: " + currentNumsList[i + 1] + " ,数3: " + currentNumsList[i + 2])
            var pre2Sum =
                currentNumsList[i] + currentNumsList[i + 1] + currentNumsList[i + 2] //8 4 12
            if (pre2Sum >= 20) {
                pre2Sum = pre2Sum - 20 //2
            } else if (pre2Sum >= 10) {
                pre2Sum = pre2Sum - 10 //2
            }
            val minSuggestValue =
                if (pre2Sum - calIntervalNum < 0) pre2Sum + 10 - calIntervalNum else pre2Sum - calIntervalNum //7
            val maxSuggestValue =
                if (pre2Sum + calIntervalNum >= 10) pre2Sum + calIntervalNum - 10 else pre2Sum + calIntervalNum //1
            AwLog.d("加法 i: $i ,pre2Sum: $pre2Sum ,minSuggestValue: $minSuggestValue ,maxSuggestValue: $maxSuggestValue")
            sortNumsList = ArrayList()
            if (minSuggestValue > maxSuggestValue) {
                AwLog.d("加法 minSuggestValue > maxSuggestValue")
                for (j in minSuggestValue..10) {
                    if (j == 10) {
                        sortNumsList.add(0)
                    } else {
                        sortNumsList.add(j)
                    }
                }
                for (k in 0..maxSuggestValue) {
                    sortNumsList.add(k)
                }
            } else if (minSuggestValue < maxSuggestValue) {
                AwLog.d("加法 minSuggestValue < maxSuggestValue")
                for (j in minSuggestValue..maxSuggestValue) {
                    sortNumsList.add(j)
                }
            } else {
                AwLog.d("加法 minSuggestValue = maxSuggestValue")
                for (j in minSuggestValue - calIntervalNum..maxSuggestValue + calIntervalNum) {
                    sortNumsList.add(j)
                }
            }
            if (i < currentNumsList.size - limitMinNums) { //14 < 18-3    13 < 18 - 4
                var isExist = false
                val nextValue = currentNumsList[i + limitMinNums] //17 = 14 + 3   17 = 13 + 4
                AwLog.d("加法 i: $i ,nextValue: $nextValue")
                for (temp in sortNumsList) {
                    if (temp == nextValue) {
                        isExist = true
                        break
                    }
                }
                AwLog.d("加法 i: " + i + " ,isExist: " + isExist + " ,结果: " + if (isExist) "顺" else "跳")
                calResultList.add(if (isExist) "顺" else "跳")
            }
        }
        val sb = StringBuffer()
        for (temp in calResultList) {
            sb.append(temp)
        }
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = sb.toString()
        resultBean.sortNumsList = sortNumsList
        return resultBean
    }

    /**
     * 计算逻辑 (减法), 临近2轮数字相减, 小于0(先加10后再做减法)
     * @param currentNumsList 当前数字集合
     * @param limitMinNums 3 前推一位数后的最近2位数相减 2 当前最近2位数相减
     * @return
     */
    fun analysisDataSubtract(
        currentNumsList: List<Int>,
        limitMinNums: Int
    ): AnalysisDataResultBean? {
        AwLog.d("================ 计算逻辑 (减法) =================")
        AwLog.d("减法 限制最少数字数量: $limitMinNums")
        if (currentNumsList.size < limitMinNums) {
            //小于limitMinNums个数, 不处理
            return null
        }
        var sortNumsList: MutableList<Int> = ArrayList() //顺数字集合
        val calResultList: MutableList<String> = ArrayList() //顺跳结果集合
        for (i in 0 until currentNumsList.size - limitMinNums + 1) {
            var pre2Sum = 0
            pre2Sum = if (currentNumsList[i] < currentNumsList[i + 1]) {
                currentNumsList[i] + 10 - currentNumsList[i + 1]
            } else {
                currentNumsList[i] - currentNumsList[i + 1]
            }
            val minSuggestValue =
                if (pre2Sum - calIntervalNum < 0) pre2Sum + 10 - calIntervalNum else pre2Sum - calIntervalNum
            val maxSuggestValue =
                if (pre2Sum + calIntervalNum >= 10) pre2Sum + calIntervalNum - 10 else pre2Sum + calIntervalNum
            AwLog.d("减法 i: $i ,pre2Sum: $pre2Sum ,minSuggestValue: $minSuggestValue ,maxSuggestValue: $maxSuggestValue")
            sortNumsList = ArrayList()
            if (minSuggestValue > maxSuggestValue) {
                AwLog.d("减法 minSuggestValue > maxSuggestValue")
                for (j in minSuggestValue..10) {
                    if (j == 10) {
                        sortNumsList.add(0)
                    } else {
                        sortNumsList.add(j)
                    }
                }
                for (k in 0..maxSuggestValue) {
                    sortNumsList.add(k)
                }
            } else if (minSuggestValue < maxSuggestValue) {
                AwLog.d("减法 minSuggestValue < maxSuggestValue")
                for (j in minSuggestValue..maxSuggestValue) {
                    sortNumsList.add(j)
                }
            } else {
                AwLog.d("减法 minSuggestValue = maxSuggestValue")
                for (j in minSuggestValue - calIntervalNum..maxSuggestValue + calIntervalNum) {
                    sortNumsList.add(j)
                }
            }
            if (i < currentNumsList.size - limitMinNums) {
                var isExist = false
                val nextValue = currentNumsList[i + limitMinNums]
                AwLog.d("减法 i: $i ,nextValue: $nextValue")
                for (temp in sortNumsList) {
                    if (temp == nextValue) {
                        isExist = true
                        break
                    }
                }
                calResultList.add(if (isExist) "顺" else "跳")
            }
        }
        val sb = StringBuffer()
        for (temp in calResultList) {
            sb.append(temp)
        }
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = sb.toString()
        resultBean.sortNumsList = sortNumsList
        return resultBean
    }

    /**
     * 计算逻辑 (减法), 临近2轮数字相减, 用大值减去小值
     * @param currentNumsList 当前数字集合
     * @param limitMinNums 3 前推一位数后的最近2位数相减 2 当前最近2位数相减
     * @return
     */
    fun analysisDataSubtract2(
        currentNumsList: List<Int>,
        limitMinNums: Int
    ): AnalysisDataResultBean? {
        AwLog.d("================ 计算逻辑 (减法---大值减去小值) =================")
        AwLog.d("减法 限制最少数字数量: $limitMinNums")
        if (currentNumsList.size < limitMinNums) {
            //小于limitMinNums个数, 不处理
            return null
        }
        var sortNumsList: MutableList<Int> = ArrayList() //顺数字集合
        val calResultList: MutableList<String> = ArrayList() //顺跳结果集合
        for (i in 0 until currentNumsList.size - limitMinNums + 1) {
            var pre2Sum = 0
            pre2Sum = if (currentNumsList[i] < currentNumsList[i + 1]) {
                currentNumsList[i + 1] - currentNumsList[i]
            } else {
                currentNumsList[i] - currentNumsList[i + 1]
            }
            val minSuggestValue =
                if (pre2Sum - calIntervalNum < 0) pre2Sum + 10 - calIntervalNum else pre2Sum - calIntervalNum
            val maxSuggestValue =
                if (pre2Sum + calIntervalNum >= 10) pre2Sum + calIntervalNum - 10 else pre2Sum + calIntervalNum
            AwLog.d("减法 i: $i ,pre2Sum: $pre2Sum ,minSuggestValue: $minSuggestValue ,maxSuggestValue: $maxSuggestValue")
            sortNumsList = ArrayList()
            if (minSuggestValue > maxSuggestValue) {
                AwLog.d("减法 minSuggestValue > maxSuggestValue")
                for (j in minSuggestValue..10) {
                    if (j == 10) {
                        sortNumsList.add(0)
                    } else {
                        sortNumsList.add(j)
                    }
                }
                for (k in 0..maxSuggestValue) {
                    sortNumsList.add(k)
                }
            } else if (minSuggestValue < maxSuggestValue) {
                AwLog.d("减法 minSuggestValue < maxSuggestValue")
                for (j in minSuggestValue..maxSuggestValue) {
                    sortNumsList.add(j)
                }
            } else {
                AwLog.d("减法 minSuggestValue = maxSuggestValue")
                for (j in minSuggestValue - calIntervalNum..maxSuggestValue + calIntervalNum) {
                    sortNumsList.add(j)
                }
            }
            if (i < currentNumsList.size - limitMinNums) {
                var isExist = false
                val nextValue = currentNumsList[i + limitMinNums]
                AwLog.d("减法 i: $i ,nextValue: $nextValue")
                for (temp in sortNumsList) {
                    if (temp == nextValue) {
                        isExist = true
                        break
                    }
                }
                calResultList.add(if (isExist) "顺" else "跳")
            }
        }
        val sb = StringBuffer()
        for (temp in calResultList) {
            sb.append(temp)
        }
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = sb.toString()
        resultBean.sortNumsList = sortNumsList
        return resultBean
    }

    /**
     * 计算逻辑 (乘法), 临近2轮数字相乘, 大于10取个位数
     * @param currentNumsList 当前数字集合
     * @param limitMinNums 可支持计算的最少数据数量,  3 前推一位数后的最近2位数相乘 2 当前最近2位数相乘
     * @return
     */
    fun analysisDataMultiply(
        currentNumsList: List<Int>,
        limitMinNums: Int
    ): AnalysisDataResultBean? {
        AwLog.d("================ 计算逻辑 (乘法) =================")
        AwLog.d("乘法 限制最少数字数量: $limitMinNums")
        if (currentNumsList.size < limitMinNums) {
            //小于limitMinNums个数, 不处理
            return null
        }
        var sortNumsList: MutableList<Int> = ArrayList() //顺数字集合
        val calResultList: MutableList<String> = ArrayList() //顺跳结果集合
        for (i in 0 until currentNumsList.size - limitMinNums + 1) {
            var pre2Sum = currentNumsList[i] * currentNumsList[i + 1]
            if (pre2Sum >= 10) {
                pre2Sum = pre2Sum % 10
            }
            val minSuggestValue =
                if (pre2Sum - calIntervalNum < 0) pre2Sum + 10 - calIntervalNum else pre2Sum - calIntervalNum
            val maxSuggestValue =
                if (pre2Sum + calIntervalNum >= 10) pre2Sum + calIntervalNum - 10 else pre2Sum + calIntervalNum
            AwLog.d("乘法 i: $i ,pre2Sum: $pre2Sum ,minSuggestValue: $minSuggestValue ,maxSuggestValue: $maxSuggestValue")
            sortNumsList = ArrayList()
            if (minSuggestValue > maxSuggestValue) {
                AwLog.d("乘法 minSuggestValue > maxSuggestValue")
                for (j in minSuggestValue..10) {
                    if (j == 10) {
                        sortNumsList.add(0)
                    } else {
                        sortNumsList.add(j)
                    }
                }
                for (k in 0..maxSuggestValue) {
                    sortNumsList.add(k)
                }
            } else if (minSuggestValue < maxSuggestValue) {
                AwLog.d("乘法 minSuggestValue < maxSuggestValue")
                for (j in minSuggestValue..maxSuggestValue) {
                    sortNumsList.add(j)
                }
            } else {
                AwLog.d("乘法 minSuggestValue = maxSuggestValue")
                for (j in minSuggestValue - calIntervalNum..maxSuggestValue + calIntervalNum) {
                    sortNumsList.add(j)
                }
            }
            if (i < currentNumsList.size - limitMinNums) {
                var isExist = false
                val nextValue = currentNumsList[i + limitMinNums]
                AwLog.d("乘法 i: $i ,nextValue: $nextValue")
                for (temp in sortNumsList) {
                    if (temp == nextValue) {
                        isExist = true
                        break
                    }
                }
                calResultList.add(if (isExist) "顺" else "跳")
            }
        }
        val sb = StringBuffer()
        for (temp in calResultList) {
            sb.append(temp)
        }
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = sb.toString()
        resultBean.sortNumsList = sortNumsList
        return resultBean
    }

    /**
     * 生成单双 AnalysisDataResultBean
     * @param currentNumsList 当前数字集合
     * @return
     */
    fun analysisDataSingleEven(currentNumsList: MutableList<Int>): AnalysisDataResultBean {
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = getSingularAndEvenNumStr(currentNumsList)
        return resultBean
    }

    /**
     * 生成大小 AnalysisDataResultBean
     * @param currentNumsList 当前数字集合
     * @return
     */
    fun analysisDataBigSmall(currentNumsList: MutableList<Int>): AnalysisDataResultBean {
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = getBigAndSmallNumStr(currentNumsList)
        return resultBean
    }

    /**
     * 生成颜色 AnalysisDataResultBean
     * @param currentNumsList 当前数字集合
     * @return
     */
    fun analysisDataRedYellow(currentNumsList: MutableList<Int>): AnalysisDataResultBean {
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = getColorNumStr(currentNumsList)
        return resultBean
    }

    /**
     * 生成中间数/边缘数 AnalysisDataResultBean
     * @param currentNumsList 当前数字集合
     * @return
     */
    fun analysisDataMidEdge(currentNumsList: MutableList<Int>): AnalysisDataResultBean {
        val resultBean = AnalysisDataResultBean()
        resultBean.calResultStr = getMidEdgeNumStr(currentNumsList)
        return resultBean
    }

    /**
     * Integer 集合转字符串
     * @param list
     * @return
     */
    fun convertListToStr(list: List<Int?>): String {
        if (AwDataUtil.isEmpty(list)) {
            return ""
        }
        val sb = StringBuffer()
        for (item in list) {
            sb.append(item)
        }
        return sb.toString()
    }

    /**
     * 获取组合交集数量
     * @param calStr
     * @param combinationStr
     * @return
     */
    fun getCombinationCount(calStr: String, combinationStr: String): Int {
        AwLog.d("appendCombinationTrendsToRecyclerView getCombinationCount calStr: $calStr ,combinationStr: $combinationStr")
        if (AwDataUtil.isEmpty(calStr)) {
            return 0
        }
        var count = 0
        val calStrArr = calStr.split("".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
        val combinationStrArr =
            combinationStr.split("".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
        for (itemCalStr in calStrArr) {  //65340039664310018260471062078156
            for (itemCombinationStr in combinationStrArr) { //12479
                if (itemCalStr == itemCombinationStr) {
                    count++
                }
            }
        }
        AwLog.d("appendCombinationTrendsToRecyclerView getCombinationCount 结果: $count")
        return count
    }
}